home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 036a / pmfinder.zip / PMFINDER.C < prev    next >
Text File  |  1991-12-05  |  25KB  |  763 lines

  1. /*
  2.  * OS/2 PM File Finder Utility - GUI SOURCE CODE
  3.  *
  4.  * LANGUAGE      : Microsoft C6.0
  5.  * MODEL         : large - MT
  6.  * ENVIRONMENT   : IBM OS/2 PM Toolkit v1.3
  7.  * STATUS        : operational
  8.  *
  9.  * Adapted from KPW's Windows 2.1 version of 07/20/88.
  10.  *
  11.  * 11/01/88 1.00 - Jerry Weldon - initial creation.
  12.  * 03/22/91 1.10 - Robert Mahoney - added multi-threading.
  13.  * 11/25/91 1.20 - Robert Mahoney - added archive file search.
  14.  *
  15.  */
  16.  /* This module contains the GUI code for the file finder */
  17.  
  18. #define INCL_DOSPROCESS
  19. #define INCL_DOSNLS
  20. #define INCL_WINWINDOWMGR
  21. #define INCL_WINDIALOGS
  22. #define INCL_WINBUTTONS
  23. #define INCL_WINENTRYFIELDS
  24. #define INCL_WINLISTBOXES
  25. #define INCL_WINMENUS
  26. #define INCL_WINFRAMEMGR
  27. #define INCL_WINSYS
  28. #define INCL_WINPOINTERS
  29. #define INCL_GPILCIDS
  30. #define NUL '\0'
  31.  
  32. #include <os2.h>
  33. #include <stdio.h>
  34. #include <stdlib.h>
  35. #include <string.h>
  36. #include <process.h>
  37.  
  38. #include "pmfinder.h"
  39.  
  40. /* global variables */
  41. BOOL        fContinue;
  42. HAB         hab;                        /* handle to anchor block   */
  43. ULONG ulWaitSem = 0;                    /* wait semaphore for threads*/
  44. HSEM  hsemWait = &ulWaitSem;
  45. static USHORT      usThreadCounter;    /* number of threads */
  46.  
  47. /* */
  48.  
  49. /*
  50.  * main( VOID ) : VOID;
  51.  *
  52.  * This function is the system entry point for the application
  53.  * and is responsible for defining the appropriate window
  54.  * classes and for processing all the messages.  Note how
  55.  * the dialog box manager is responsible for the operation of
  56.  * the file finder window.
  57.  *
  58.  */
  59.  
  60. VOID cdecl main( VOID )
  61. {
  62.   HMQ         hmq;                        /* handle to message queue  */
  63.   HWND        hwnd;                       /* handle to main window    */
  64.   HPOINTER    hptr;                       /* handle to window's icon  */
  65.  
  66.   /* initialize thread & create message queue */
  67.   hab = WinInitialize( 0 );
  68.   hmq = WinCreateMsgQueue( hab, 0 );
  69.  
  70.   /* load the main dialog */
  71.   hwnd = WinLoadDlg(
  72.     HWND_DESKTOP,
  73.     HWND_DESKTOP,
  74.     FinderDlgProc,
  75.     NUL,
  76.     ID_FINDER,
  77.     NUL
  78.   );
  79.  
  80.   /* set an icon for the dialog */
  81.   hptr = WinLoadPointer( HWND_DESKTOP, NUL, ID_FINDER );
  82.   WinSendMsg( hwnd, WM_SETICON, (MPARAM)hptr, 0L );
  83.  
  84.   /* process the dialog */
  85.   WinProcessDlg( hwnd );
  86.  
  87.   /* destroy the dialog and its icon */
  88.   WinDestroyWindow( hwnd );
  89.   WinDestroyPointer( hptr );
  90.  
  91.   /* destroy message queue & terminate thread */
  92.   WinDestroyMsgQueue( hmq );
  93.   WinTerminate( hab );
  94. }
  95.  
  96. /* */
  97.  
  98. /*
  99.  * FinderDlgProc( hwnd, usMsg, mp1, mp2 ) : MRESULT;
  100.  *
  101.  *    hwnd          handle to main dialog window
  102.  *    usMsg         message number
  103.  *    mp1           message parameter 1
  104.  *    mp2           message parameter 2
  105.  *
  106.  * This function is responsible for processing all the messages
  107.  * which relate to the file finder dialog box.  This mainly
  108.  * involves the definition and retrieval of the various
  109.  * events generated by the user.
  110.  *
  111.  */
  112.  
  113. MRESULT EXPENTRY FinderDlgProc(
  114.   HWND        hwnd,
  115.   USHORT      usMsg,
  116.   MPARAM      mp1,
  117.   MPARAM      mp2 )
  118. {
  119.   MRESULT     mresRtnVal;                 /* function return value    */
  120.   BOOL        fPassToDef;                 /* pass to def window proc? */
  121.   static int iSaveLength;
  122.   static BOOL fSearch;
  123.  
  124.  
  125.   mresRtnVal = FALSE;
  126.   fPassToDef = FALSE;
  127.  
  128.   switch ( usMsg ) {
  129.  
  130.     case WM_INITDLG:
  131.          InitDlgBox(hwnd);
  132.          iSaveLength = 0;
  133.          fSearch = FALSE;
  134.       break;
  135.  
  136.     case WM_CONTROL:
  137.       switch ( SHORT1FROMMP( mp1 ) ) {
  138.  
  139.         case IDCB_ARCHIVE:
  140.           WinSendDlgItemMsg(hwnd,IDRB_ALSO,
  141.                             BM_SETCHECK,
  142.                             MPFROMSHORT(TRUE),NUL);
  143.            break;
  144.         case IDD_PATTERN:
  145.           if ( SHORT2FROMMP( mp1 ) == EN_CHANGE )
  146.             /* enable/disable search button */
  147.             WinEnableWindow(
  148.               WinWindowFromID( hwnd, IDD_SEARCH ),
  149.               WinQueryWindowTextLength(
  150.                 WinWindowFromID( hwnd, IDD_PATTERN )));
  151.           else
  152.             fPassToDef = TRUE;
  153.           break;
  154.  
  155.         default:
  156.           fPassToDef = TRUE;
  157.           break;
  158.  
  159.       }
  160.       break;
  161.  
  162.     case WM_THREAD_DONE:
  163.         usThreadCounter--;
  164.         /* When 0 all threads will have finished */
  165.         if (!usThreadCounter)
  166.         {
  167.            /* set status text message */
  168.             WinSetWindowText(WinWindowFromID(hwnd,IDT_STATUS),
  169.                              "Press Search to start");
  170.             /* check for null search operation */
  171.             if ( !WinSendDlgItemMsg(
  172.               hwnd,
  173.               IDD_FILES,
  174.               LM_QUERYITEMCOUNT,
  175.               0L,
  176.               0L
  177.             ) )
  178.               WinMessageBox(
  179.                 HWND_DESKTOP,
  180.                 hwnd,
  181.                 "No files found matching criteria!",
  182.                 "File Finder",
  183.                 0,
  184.                 MB_OK | MB_ICONHAND
  185.               );
  186.             /* change button text back to Search */
  187.             WinSetWindowText(
  188.               WinWindowFromID( hwnd, IDD_SEARCH ), "~Search");
  189.             fSearch = FALSE;
  190.         }
  191.         break;
  192.  
  193.     case WM_COMMAND:
  194.       switch ( COMMANDMSG( &usMsg )->cmd ) {
  195.  
  196.         case IDD_SEARCH: /* search using path */
  197.         case DID_OK:
  198.           if (!fSearch)
  199.           {
  200.              fSearch = TRUE;
  201.             /* change button text to Stop */
  202.              WinSetWindowText(WinWindowFromID( hwnd, IDD_SEARCH ),
  203.                                "~Stop");
  204.              StartSearch(hwnd);
  205.           }
  206.           else
  207.             fContinue = FALSE;
  208.           break;
  209.  
  210.  
  211.         case IDD_QUIT:
  212.           fContinue = FALSE;
  213.           if (usThreadCounter)
  214.              WinPostMsg(hwnd,WM_COMMAND,
  215.                         MPFROMSHORT(IDD_QUIT),
  216.                         MPFROMSHORT(CMDSRC_PUSHBUTTON));
  217.           else
  218.              WinDismissDlg( hwnd, TRUE );
  219.           break;
  220.  
  221.         case IDM_ABOUT:
  222.           WinDlgBox( HWND_DESKTOP, hwnd, AboutDlgProc, NUL, IDD_ABOUTDLG, NUL );
  223.           break;
  224.  
  225.         case DID_CANCEL:
  226.           /* don't quit the program when escape key is pressed */
  227.           fContinue = FALSE;
  228.           break;
  229.  
  230.         default:
  231.           fPassToDef = TRUE;
  232.           break;
  233.  
  234.       }
  235.       break;
  236.  
  237.     case WM_MEASUREITEM:
  238.       if ( SHORT1FROMMP( mp1 ) == IDD_FILES ) {
  239.  
  240.         HPS         hps;                  /* handle to window PS      */
  241.         FONTMETRICS *pfm ;                /* info on font             */
  242.         int iLen;
  243.  
  244.         pfm = malloc(sizeof(FONTMETRICS));
  245.         hps = WinGetPS( hwnd );
  246.         GpiQueryFontMetrics(hps, (long)sizeof(FONTMETRICS), pfm);
  247.         iLen = (int)(long)WinSendMsg(WinWindowFromID(hwnd,SHORT1FROMMP(mp1)),
  248.                                      LM_QUERYITEMTEXTLENGTH,
  249.                                      mp2, 0L);
  250.         iSaveLength = (iLen < iSaveLength ) ? iSaveLength : iLen;
  251.         /* return the height and length of the longest listbox item */
  252. //      mresRtnVal = MRFROM2SHORT( pfm->lMaxBaselineExt+2,(pfm->lMaxCharInc *iSaveLength) );
  253.         mresRtnVal = MRFROM2SHORT( pfm->lMaxBaselineExt+2, ((pfm->lAveCharWidth *iSaveLength)+(iSaveLength*2)) );
  254.         WinReleasePS( hps );
  255.         free(pfm);
  256.  
  257.       }
  258.       break;
  259.  
  260.     case WM_DRAWITEM:
  261.       if ( SHORT1FROMMP( mp1 ) == IDD_FILES ) {
  262.  
  263.         int len;
  264.         COLOR           clrFG, clrBG;       /* Foreground/Background colors */
  265.  
  266.         OWNERITEM FAR *oi = (OWNERITEM FAR *)mp2;
  267.         char *str = NULL;
  268.  
  269.           len = (int)(long)WinSendMsg(oi->hwnd, LM_QUERYITEMTEXTLENGTH, MPFROMSHORT(oi->idItem), 0L);
  270.           if(len)
  271.           {
  272.               str = malloc(len);
  273.               if (str)
  274.               {
  275.                  WinSendMsg(oi->hwnd, LM_QUERYITEMTEXT, MPFROM2SHORT(oi->idItem, len), MPFROMP(str));
  276.                  if ((strstr(str,"File Error - ")) || (strstr(str,"LzhFile Error")))
  277.                  {
  278.                     if (oi->fsState != TRUE)   /* should cell be highlited?*/
  279.                     {
  280.                         clrFG = CLR_BLACK;
  281.                         clrBG = CLR_CYAN;
  282.                     }
  283.                     else
  284.                     {
  285.                         clrFG = CLR_CYAN;
  286.                         clrBG = CLR_BLACK;
  287.                     }
  288.  
  289.                      WinDrawText(oi->hps, len, str,
  290.                                  &oi->rclItem, clrFG, clrBG,
  291.                                  DT_LEFT | DT_VCENTER | DT_ERASERECT);
  292.                  }
  293.                  else
  294.                  {
  295.                     if (!strstr(str,"-->"))
  296.                     {
  297.                        if (oi->fsState != TRUE)   /* should cell be highlited?*/
  298.                        {
  299.                            clrFG = CLR_DARKBLUE;
  300.                            clrBG = CLR_WHITE;
  301.                        }
  302.                        else
  303.                        {
  304.                            clrBG = CLR_DARKBLUE;
  305.                            clrFG = CLR_WHITE;
  306.                        }
  307.                        WinDrawText(oi->hps, len, str,
  308.                                    &oi->rclItem, clrFG, clrBG,
  309.                                    DT_LEFT | DT_VCENTER | DT_ERASERECT);
  310.                     }
  311.                     else
  312.                     {
  313.                        if (strstr(str,"ZIP-->"))
  314.                        {
  315.                           if (oi->fsState != TRUE)   /* should cell be highlited?*/
  316.                           {
  317.                               clrFG = CLR_DARKRED;
  318.                               clrBG = CLR_WHITE;
  319.                           }
  320.                           else
  321.                           {
  322.                               clrBG = CLR_DARKRED;
  323.                               clrFG = CLR_WHITE;
  324.                           }
  325.                           WinDrawText(oi->hps, len, str,
  326.                                       &oi->rclItem, clrFG, clrBG,
  327.                                       DT_LEFT | DT_VCENTER | DT_ERASERECT);
  328.                        }
  329.                        else
  330.                           if (strstr(str,"LZH-->"))
  331.                           {
  332.                              if (oi->fsState != TRUE)   /* should cell be highlited?*/
  333.                              {
  334.                                  clrFG = CLR_BLACK;
  335.                                  clrBG = CLR_WHITE;
  336.                              }
  337.                              else
  338.                              {
  339.                                  clrBG = CLR_BLACK;
  340.                                  clrFG = CLR_WHITE;
  341.                              }
  342.                              WinDrawText(oi->hps, len, str,
  343.                                          &oi->rclItem, clrFG, clrBG,
  344.                                          DT_LEFT | DT_VCENTER | DT_ERASERECT);
  345.                           }
  346.                           else
  347.                              if (strstr(str,"ARC-->") || strstr(str,"PAK-->"))
  348.                              {
  349.                                 if (oi->fsState != TRUE)   /* should cell be highlited?*/
  350.                                 {
  351.                                     clrFG = CLR_DARKGREEN;
  352.                                     clrBG = CLR_WHITE;
  353.                                 }
  354.                                 else
  355.                                 {
  356.                                     clrBG = CLR_DARKGREEN;
  357.                                     clrFG = CLR_WHITE;
  358.                                 }
  359.                                 WinDrawText(oi->hps, len, str,
  360.                                             &oi->rclItem, clrFG, clrBG,
  361.                                             DT_LEFT | DT_VCENTER | DT_ERASERECT);
  362.                              }
  363.                     }
  364.                  }
  365.                  free(str);
  366.               }
  367.               oi->fsState = oi->fsStateOld = FALSE;
  368.           }
  369.           return((MRESULT)TRUE);
  370.  
  371.       }
  372.       break;
  373.  
  374.     case WM_MINMAXFRAME:
  375.       {
  376.         PSWP        pswp;                     /* pos change structure */
  377.  
  378.         /* hide list box when minimized so it doesn't overwrite icon */
  379.         pswp = PVOIDFROMMP( mp1 );
  380.         WinShowWindow(
  381.           WinWindowFromID( hwnd, IDD_FILES ),
  382.           !(pswp->fs & SWP_MINIMIZE)
  383.         );
  384.       }
  385.       break;
  386.  
  387.     default:
  388.       fPassToDef = TRUE;
  389.       break;
  390.  
  391.   }
  392.  
  393.   /* pass to def dialog proc if needed */
  394.   if ( fPassToDef )
  395.     mresRtnVal = WinDefDlgProc( hwnd, usMsg, mp1, mp2 );
  396.  
  397.   return mresRtnVal;
  398. }
  399.  
  400. /* */
  401.  
  402. /*
  403.  * AboutDlgProc( hwndDlg, usMsg, mp1, mp2 ) : MRESULT;
  404.  *
  405.  *    hwndDlg        handle to dialog box
  406.  *    usMsg          message number
  407.  *    mp1            message parameter 1
  408.  *    mp2            message parameter 2
  409.  *
  410.  * This is the dialog procedure for the About dialog box.
  411.  *
  412.  */
  413.  
  414. MRESULT EXPENTRY AboutDlgProc( HWND hwndDlg, USHORT usMsg, MPARAM mp1, MPARAM mp2 )
  415. {
  416.   MRESULT       mresRtnVal;                 /* function return value  */
  417.   BOOL          fPassToDef;                 /* pass to def dlg proc?  */
  418.  
  419.   mresRtnVal = FALSE;
  420.   fPassToDef = FALSE;
  421.  
  422.   switch ( usMsg ) {
  423.  
  424.     case WM_INITDLG:
  425.       CenterPopup( hwndDlg, HWNDOWNER( hwndDlg ) );
  426.       break;
  427.  
  428.     case WM_COMMAND:
  429.       switch ( COMMANDMSG( &usMsg )->cmd ) {
  430.         case DID_OK:
  431.           WinDismissDlg( hwndDlg, TRUE );
  432.           break;
  433.         default:
  434.           fPassToDef = TRUE;
  435.           break;
  436.       }
  437.       break;
  438.  
  439.     default:
  440.       fPassToDef = TRUE;
  441.       break;
  442.  
  443.   }
  444.  
  445.   if ( fPassToDef )
  446.     mresRtnVal = WinDefDlgProc( hwndDlg, usMsg, mp1, mp2 );
  447.  
  448.   return mresRtnVal;
  449. }
  450.  
  451. /* */
  452.  
  453. /*
  454.  * CenterPopup( hwndPopup, hwndCenter ) : VOID;
  455.  *
  456.  *    hwndPopup      handle to popup window to center
  457.  *    hwndCenter     handle to window within which to center
  458.  *
  459.  * This function centers the popup window within the given window.
  460.  * To center within the entire desktop, pass HWND_DESKTOP as the
  461.  * hwndCenter parameter.  If the centered popup would be partially
  462.  * or completely off the edges of the screen, it is moved to be
  463.  * within the borders of the screen.
  464.  *
  465.  */
  466.  
  467. static VOID CenterPopup(
  468.   HWND        hwndPopup,
  469.   HWND        hwndCenter )
  470. {
  471.   LONG        cxPopup;                            /* popup width      */
  472.   LONG        cyPopup;                            /* popup height     */
  473.   LONG        cxCenter;                           /* parent width     */
  474.   LONG        cyCenter;                           /* parent height    */
  475.   LONG        cxScreen;                           /* screen width     */
  476.   LONG        cyScreen;                           /* screen height    */
  477.   RECTL       rclCenter;                          /* parent rectangle */
  478.   RECTL       rclPopup;                           /* popup rectangle  */
  479.  
  480.   /* get window rects for popup and center */
  481.   if ( !hwndCenter || (hwndCenter == HWND_DESKTOP) ) {
  482.     rclCenter.xLeft = 0;
  483.     rclCenter.yBottom = 0;
  484.     rclCenter.xRight = WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN );
  485.     rclCenter.yTop = WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN );
  486.   } else
  487.     WinQueryWindowRect( hwndCenter, &rclCenter );
  488.   WinQueryWindowRect( hwndPopup, &rclPopup );
  489.  
  490.   /* convert to screen coordinates */
  491.   MAPWINDOWRECTS( hwndPopup, HWND_DESKTOP, &rclPopup, 1 );
  492.   MAPWINDOWRECTS( hwndCenter, HWND_DESKTOP, &rclCenter, 1 );
  493.  
  494.   /* calculate window widths */
  495.   cxPopup = ABS(rclPopup.xRight - rclPopup.xLeft);
  496.   cyPopup = ABS(rclPopup.yTop - rclPopup.yBottom);
  497.   cxCenter = ABS(rclCenter.xRight - rclCenter.xLeft);
  498.   cyCenter = ABS(rclCenter.yTop - rclCenter.yBottom);
  499.  
  500.   /* center popup within parent */
  501.   rclPopup.xLeft = rclCenter.xLeft + (cxCenter-cxPopup)/2;
  502.   rclPopup.yBottom = rclCenter.yBottom + (cyCenter-cyPopup)/2;
  503.  
  504.   /* adjust position if hanging off on right or left */
  505.   cxScreen = WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN );
  506.   if ( rclPopup.xLeft+cxPopup >= cxScreen )
  507.     rclPopup.xLeft = (cxScreen - 1) - cxPopup;
  508.   if ( rclPopup.xLeft < 0 )
  509.     rclPopup.xLeft = 0;
  510.  
  511.   /* adjust position if hanging off on top or bottom */
  512.   cyScreen = WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN );
  513.   if ( rclPopup.yBottom+cyPopup >= cyScreen )
  514.     rclPopup.yBottom = (cyScreen - 1) - cyPopup;
  515.   if ( rclPopup.yBottom < 0 )
  516.     rclPopup.yBottom = 0;
  517.  
  518.   /* convert to parent coordinates */
  519.   rclPopup.xRight = rclPopup.yTop = 0;  /* don't care about topright */
  520.   MAPWINDOWRECTS( HWND_DESKTOP, HWNDPARENT( hwndPopup ), &rclPopup, 1 );
  521.  
  522.   /* place popup window using parent coordinates */
  523.   WinSetWindowPos(
  524.     hwndPopup,
  525.     NUL,
  526.     LOUSHORT( rclPopup.xLeft ),
  527.     LOUSHORT( rclPopup.yBottom ),
  528.     0,
  529.     0,
  530.     SWP_MOVE
  531.   );
  532. }
  533. /*
  534.  * StartSearch( hwnd ) : VOID;
  535.  *
  536.  *    hwnd           handle to the dialog window
  537.  *
  538.  * This function starts the file search procedure.
  539.  * If archive file search is requested it will search the selected
  540.  * archive files for the pattern.
  541.  *
  542.  */
  543. void StartSearch(HWND hwnd)
  544. {
  545.       USHORT    iItem;            /* temporary loop variable    */
  546.       HWND      hwndListBox;      /* handle to list box         */
  547.       CHAR      szDrive[8];       /* drive specification string */
  548.       int       i;
  549.       TID         ScanTID    ;   /* scan thread id           */
  550.       BOOL        bArchive;      /* search archives?         */
  551.       BOOL        bOnly ;        /* only search archives?         */
  552.       static   SCANTHREADPARM stp;
  553.  
  554.       usThreadCounter = 0;
  555.  
  556.       /* set status text message */
  557.          WinSetWindowText(WinWindowFromID(hwnd,IDT_STATUS),
  558.                           "Search in progress");
  559.       /* retrieve search pattern & erase current file list */
  560.       WinQueryDlgItemText(
  561.         hwnd,
  562.         IDD_PATTERN,
  563.         sizeof(stp.szPattern),
  564.         stp.szPattern
  565.       );
  566.       WinSendDlgItemMsg( hwnd, IDD_FILES, LM_DELETEALL, 0L, 0L );
  567.  
  568.     /* search archives ?  */
  569.     bArchive = SHORT1FROMMR(WinSendDlgItemMsg(hwnd,IDCB_ARCHIVE,
  570.                       BM_QUERYCHECK,
  571.                       NUL,NUL));
  572.  
  573.     /* search only archives for mask ?  */
  574.     bOnly = SHORT1FROMMR(WinSendDlgItemMsg(hwnd,IDRB_ONLY,
  575.                       BM_QUERYCHECK,
  576.                       NUL,NUL));
  577.       /* perform search on each selected drive */
  578.       i=0;
  579.       hwndListBox = WinWindowFromID( hwnd, IDD_DRIVES );
  580.       iItem = LIT_FIRST;
  581.       while (
  582.         (iItem = SHORT1FROMMR( WinSendMsg(
  583.           hwndListBox,
  584.           LM_QUERYSELECTION,
  585.           MPFROMSHORT( iItem ),
  586.           0L ) )) != LIT_NONE
  587.       ) {
  588.  
  589.         /* define file specification */
  590.         WinSendMsg(
  591.           hwndListBox,
  592.           LM_QUERYITEMTEXT,
  593.           MPFROM2SHORT( iItem, sizeof(szDrive) ),
  594.           MPFROMP( szDrive )
  595.         );
  596.         stp.drive_spec[i] = szDrive[2];
  597.         i++;
  598.       }
  599.  
  600.       if(i<27)
  601.         stp.drive_spec[i] = NUL;
  602.  
  603.  
  604.       stp.hwndListBox = WinWindowFromID( hwnd, IDD_FILES );
  605.       stp.hwndDlg = hwnd;
  606.       /* A null archive field indicates regular search */
  607.       stp.szArchive[0] = NUL;
  608.        ScanTID = 0;
  609.       if (!bOnly)
  610.       {
  611.          DosSemSet(hsemWait);
  612.          if (-1==(ScanTID =_beginthread(ScanThread,NULL,STACKSIZE,&stp)))
  613.            WinAlarm(HWND_DESKTOP,WA_ERROR);
  614.            usThreadCounter++;
  615.          DosSemWait(hsemWait,(ULONG)-1) ;
  616.       }
  617.  
  618.       /* if search archive then spin a thread to search */
  619.       if (bArchive)
  620.       {
  621.          /* perform search for each selected archive */
  622.          i=0;
  623.          hwndListBox = WinWindowFromID( hwnd, IDLB_ARCHIVE );
  624.          iItem = LIT_FIRST;
  625.          while (
  626.            (iItem = SHORT1FROMMR( WinSendMsg(
  627.              WinWindowFromID(hwnd,IDLB_ARCHIVE),
  628.              LM_QUERYSELECTION,
  629.              MPFROMSHORT( iItem ),
  630.              0L ) )) != LIT_NONE
  631.          ) {
  632.  
  633.            /* define file specification */
  634.            WinSendMsg(
  635.              WinWindowFromID(hwnd,IDLB_ARCHIVE),
  636.              LM_QUERYITEMTEXT,
  637.              MPFROM2SHORT( iItem, sizeof(stp.szArchive)),
  638.              MPFROMP( stp.szArchive ) );
  639.            if (-1==(ScanTID =_beginthread(ScanThread,NULL,STACKSIZE,&stp)))
  640.               WinAlarm(HWND_DESKTOP,WA_ERROR);
  641.               usThreadCounter++;
  642.               DosSemSetWait(hsemWait,-1);
  643.          }
  644.       }
  645.  
  646. }
  647. void InitDlgBox(HWND hwnd)
  648. {
  649.         HWND        hwndSysMenu;          /* system menu handle       */
  650.         USHORT      idSysMenu;            /* system menu id           */
  651.         MENUITEM    miSysMenu;            /* system menu item info    */
  652.         MENUITEM    miAbout;              /* About menu item info     */
  653.         USHORT      usCurDrive;           /* current drive number     */
  654.         ULONG       flDrives;             /* available logical drives */
  655.         CHAR        szDrive[6];           /* temporary drive string   */
  656.         USHORT      iItem;                /* temporary loop variable  */
  657.         USHORT      cszList;              /* # of selected drives     */
  658. static  HWND        hwndListBox;          /* handle to list box       */
  659.  
  660.         /* add About item to system menu */
  661.         if ( hwndSysMenu = WinWindowFromID( hwnd, FID_SYSMENU ) ) {
  662.  
  663.           /* get handle of system submenu */
  664.           idSysMenu = SHORT1FROMMR( WinSendMsg( hwndSysMenu, MM_ITEMIDFROMPOSITION, MPFROMSHORT( 0 ), 0L ) );
  665.           WinSendMsg( hwndSysMenu, MM_QUERYITEM, MPFROM2SHORT( idSysMenu, FALSE ), MPFROMP( &miSysMenu ) );
  666.           hwndSysMenu = miSysMenu.hwndSubMenu;
  667.  
  668.           /* add menu separator */
  669.           miAbout.iPosition = MIT_END;
  670.           miAbout.afStyle = MIS_SEPARATOR;
  671.           miAbout.afAttribute = 0;
  672.           miAbout.id = 0;
  673.           miAbout.hwndSubMenu = NUL;
  674.           miAbout.hItem = NUL;
  675.           WinSendMsg( hwndSysMenu, MM_INSERTITEM, MPFROMP( &miAbout ), NUL );
  676.  
  677.           /* add About item */
  678.           miAbout.afStyle = MIS_TEXT;
  679.           miAbout.id = IDM_ABOUT;
  680.           WinSendMsg( hwndSysMenu, MM_INSERTITEM, MPFROMP( &miAbout ), MPFROMP( "A~bout..." ) );
  681.  
  682.         }
  683.  
  684.         /* center dialog box on screen */
  685.         CenterPopup( hwnd, HWND_DESKTOP );
  686.  
  687.         /* define search pattern */
  688.         WinSetDlgItemText( hwnd, IDD_PATTERN, "*.*" );
  689.  
  690.         /* initialize drive list */
  691.         DosQCurDisk( &usCurDrive, &flDrives );
  692.         szDrive[0] = '[';
  693.         szDrive[1] = '-';
  694.         szDrive[3] = '-';
  695.         szDrive[4] = ']';
  696.         szDrive[5] = '\0';
  697.         for ( szDrive[2] = 'A'; szDrive[2] <= 'Z'; szDrive[2]++ ) {
  698.           if ( flDrives & 1 )
  699.             WinSendDlgItemMsg(
  700.               hwnd,
  701.               IDD_DRIVES,
  702.               LM_INSERTITEM,
  703.               MPFROMSHORT( LIT_END ),
  704.               MPFROMP( szDrive )
  705.             );
  706.           flDrives >>= 1;
  707.         }
  708.  
  709.         /* select all fixed drives */
  710.         hwndListBox = WinWindowFromID( hwnd, IDD_DRIVES );
  711.         cszList = SHORT1FROMMR( WinSendMsg(
  712.           hwndListBox,
  713.           LM_QUERYITEMCOUNT,
  714.           0L,
  715.           0L
  716.         ) );
  717.         for ( iItem = 0; iItem < cszList; iItem++ ) {
  718.           WinSendMsg(
  719.             hwndListBox,
  720.             LM_QUERYITEMTEXT,
  721.             MPFROM2SHORT( iItem, sizeof(szDrive) ),
  722.             MPFROMP( szDrive )
  723.           );
  724.           if ( szDrive[2] >= 'C' )
  725.             WinSendMsg(
  726.               hwndListBox,
  727.               LM_SELECTITEM,
  728.               MPFROMSHORT( iItem ),
  729.               MPFROMSHORT( TRUE )
  730.             );
  731.         }
  732.             /* disable cancel button  */
  733.             WinEnableWindow(
  734.               WinWindowFromID( hwnd, IDD_CANCEL ), FALSE);
  735.          /* add the archive extensions to listbox */
  736.           WinSendDlgItemMsg(hwnd,
  737.                             IDLB_ARCHIVE,
  738.                             LM_INSERTITEM,
  739.                             MPFROMSHORT( LIT_END ),
  740.                             MPFROMP( "ZIP" ) );
  741.           WinSendDlgItemMsg(hwnd,
  742.                             IDLB_ARCHIVE,
  743.                             LM_INSERTITEM,
  744.                             MPFROMSHORT( LIT_END ),
  745.                             MPFROMP( "LZH" ) );
  746.           WinSendDlgItemMsg(hwnd,
  747.                             IDLB_ARCHIVE,
  748.                             LM_INSERTITEM,
  749.                             MPFROMSHORT( LIT_END ),
  750.                             MPFROMP( "ARC" ) );
  751.           WinSendDlgItemMsg(hwnd,
  752.                             IDLB_ARCHIVE,
  753.                             LM_INSERTITEM,
  754.                             MPFROMSHORT( LIT_END ),
  755.                             MPFROMP( "PAK" ) );
  756.             WinSendMsg( WinWindowFromID(hwnd,IDLB_ARCHIVE),
  757.                         LM_SELECTITEM,
  758.                         MPFROMSHORT( 0 ),
  759.                         MPFROMSHORT( TRUE )  );
  760.          WinSetWindowText(WinWindowFromID(hwnd,IDT_STATUS),
  761.                           "Press Search to start");
  762. }
  763.